package com.zbkj.admin.controller.merchant;

import com.github.pagehelper.PageInfo;
import com.zbkj.admin.model.vo.MerchantShareDetailResponse;
import com.zbkj.admin.service.AdminShareService;
import com.zbkj.dal.base.enums.show.EnumShowVO;
import com.zbkj.dal.base.page.CommonPage;
import com.zbkj.dal.base.result.CommonResult;
import com.zbkj.dal.common.utils.SecurityUtil;
import com.zbkj.dal.pojo.request.OrderSendRequest;
import com.zbkj.dal.pojo.request.PageParamRequest;
import com.zbkj.dal.pojo.request.ShareQueryRequest;
import com.zbkj.dal.pojo.request.ba.ConcludeShareRequest;
import com.zbkj.dal.pojo.request.ba.UpdateFinalResultRequest;
import com.zbkj.dal.pojo.request.ba.UpdateInitialResultRequest;
import com.zbkj.dal.pojo.response.ba.ShareDetailResponse;
import com.zbkj.dal.pojo.response.ba.ShareResponse;
import com.zbkj.dal.pojo.vo.LoginUserVo;
import com.zbkj.dal.pojo.vo.LogisticsResultVo;
import com.zbkj.service.service.ShareService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("api/admin/merchant/share")
@Api(tags = "奢品共享")
public class MerchantShareController {
    @Autowired
    private ShareService shareService;

    @Resource
    private AdminShareService adminShareService;

    // 订单状态列表
    @ApiOperation(value = "订单状态列表")
    @RequestMapping(value = "/order/status", method = RequestMethod.GET)
    public CommonResult<List<EnumShowVO<String>>> getOrderStatusList() {
        return CommonResult.success(shareService.getOrderStatusList());
    }

    //    @PreAuthorize("hasAuthority('platform:seckill:time:interval:add')")
    @ApiOperation(value = "分页获取共享信息")
    @RequestMapping(value = "/pageShares", method = RequestMethod.POST)
    public CommonResult<CommonPage<ShareResponse>> querySharesPaged(@RequestBody ShareQueryRequest shareQueryRequest, PageParamRequest pageParamRequest) {
        PageInfo<ShareResponse> sharePageInfo = adminShareService.querySharesPaged(shareQueryRequest, pageParamRequest);
        return CommonResult.success(CommonPage.restPage(sharePageInfo));
    }

    @ApiOperation(value = "奢品共享信息详情")
    @RequestMapping(value = "/detail/{orderNo}", method = RequestMethod.GET)
    public CommonResult<MerchantShareDetailResponse> detail(@PathVariable("orderNo") String orderNo) {
        return CommonResult.success(adminShareService.detail(orderNo));
    }

    @ApiOperation(value = "评估判定共享信息")
    @RequestMapping(value = "/conclude", method = RequestMethod.POST)
    public CommonResult<Boolean> conclude(@RequestBody ConcludeShareRequest concludeShareRequest) {
        LoginUserVo loginUserVo = SecurityUtil.getLoginUserVo();
        concludeShareRequest.setOperatorId(loginUserVo.getUser().getId());
        return CommonResult.success(shareService.conclude(concludeShareRequest));
    }

    @ApiOperation(value = "创建商品")
    @RequestMapping(value = "/createProduct/{id}", method = RequestMethod.POST)
    public CommonResult<Boolean> createProduct(@PathVariable("id") Integer id) {
        return CommonResult.success(shareService.createProduct(id));
    }

    // 修改初评结果
    @ApiOperation(value = "修改初评结果")
    @RequestMapping(value = "/updateInitialResult", method = RequestMethod.POST)
    public CommonResult<Void> updateInitialResult(@RequestBody UpdateInitialResultRequest req) {
        shareService.updateShareInitialEvaluationResult(req);
        return CommonResult.success();
    }

    // 确认收货
    @ApiOperation(value = "确认收货")
    @RequestMapping(value = "/confirmReceipt", method = RequestMethod.POST)
    public CommonResult<Boolean> confirmReceipt(@RequestParam("orderNo") String orderNo) {
        LoginUserVo loginUserVo = SecurityUtil.getLoginUserVo();
        return CommonResult.success(shareService.confirmReceipt(orderNo, loginUserVo.getUser().getId()));
    }

    // 确认提货
    @ApiOperation(value = "确认提货")
    @RequestMapping(value = "/confirmDelivery", method = RequestMethod.POST)
    public CommonResult<Boolean> confirmDelivery(@RequestParam("orderNo") String orderNo, @RequestParam("deliveryCode") String deliveryCode) {
        LoginUserVo loginUserVo = SecurityUtil.getLoginUserVo();
        return CommonResult.success(shareService.confirmDelivery(orderNo, deliveryCode, loginUserVo.getUser().getId()));
    }

    // 退回中发货
    @ApiOperation(value = "退回中发货")
    @RequestMapping(value = "/return/delivery", method = RequestMethod.POST)
    public CommonResult<Boolean> delivery(@RequestBody OrderSendRequest request) {
        SecurityUtil.getLoginUserVo();
        return CommonResult.success(shareService.delivery(request));
    }

    @ApiOperation(value = "提交终评结果")
    @RequestMapping(value = "/submitFinalResult", method = RequestMethod.POST)
    public CommonResult<Void> submitFinalResult(@RequestBody UpdateFinalResultRequest request) {
        shareService.updateShareFinalEvaluationResult(request);
        return CommonResult.success();
    }


    // 修改终评估价
    @ApiOperation(value = "修改终评估价")
    @RequestMapping(value = "/updateEstimatePrice", method = RequestMethod.POST)
    public CommonResult<Boolean> updateEstimatePrice(@RequestParam("orderNo") String orderNo, @RequestParam("estimatePrice") String estimatePrice) {
        return CommonResult.success(shareService.updateShareEstimatePrice(orderNo, estimatePrice));
    }

    // 查看订单物流轨迹
    @ApiOperation(value = "查看订单物流轨迹")
    @RequestMapping(value = "/logistics", method = RequestMethod.GET)
    public CommonResult<List<LogisticsResultVo>> getLogistics(@RequestParam("orderNo") String orderNo) {
        return CommonResult.success(shareService.getLogistics(orderNo));
    }

}
